package com.jeeplus.test.jlnu.archivalInfo.controller;

import com.jeeplus.test.jlnu.archivalInfo.service.ArchivalInfoService;
import com.jeeplus.test.tools.resp.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/archivalHanging")
public class ArchivalHangingController {

    @Autowired
    private ArchivalInfoService archivalInfoService;

    @ApiOperation("档案挂接")
    @PostMapping("/hanging")
    //接收最多10个文件
    public R hanging(@RequestParam("file") MultipartFile[] files, HttpServletRequest request) {
        if (archivalInfoService.hanging(files,request)>0){
            return R.suc("挂接成功");
        }else {
            return R.error();
        }
    }
    @GetMapping("/list")
    public ResponseEntity<Map<String, Object>> getFailedFiles(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize
    ) {
        return ResponseEntity.ok(archivalInfoService.getFailedFiles(pageNum, pageSize));
    }
    @ApiOperation("通过id查询文件对象")
    @GetMapping("/queryFileById")
    public R queryFileById(@RequestParam("fileId") String fileId) {
        return R.suc(archivalInfoService.queryFileById(fileId));
    }


}
